package cn.yeyiu.sexyiu.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
import cn.yeyiu.sexyiu.R;
import cn.yeyiu.sexyiu.adapter.VideoGuessAdapter;
import cn.yeyiu.util.VideoUtil;

/**
 * GuessActivity 类似 douyin 滑动视频 实现方式1
 * 基于 pagerSnapHelper 实现
 */

public class GuessActivity extends AppCompatActivity {
    private VideoGuessAdapter adapter;
    private Handler handler;
    LinearLayoutManager layoutManager;
    private RecyclerView recyclerView;
    private PagerSnapHelper snapHelper;

    /* access modifiers changed from: protected */
    @Override // androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_guess);
        getWindow().getDecorView().setSystemUiVisibility(5124);
        viewInit();
        setRecyclerView();
        handlerInit();
        videoInit();
        eventInit();
    }

    /* access modifiers changed from: package-private */
    public void viewInit() {
        this.recyclerView = (RecyclerView) findViewById(R.id.rv_full_video);
        PagerSnapHelper pagerSnapHelper = new PagerSnapHelper();
        this.snapHelper = pagerSnapHelper;
        pagerSnapHelper.attachToRecyclerView(this.recyclerView);
    }

    public void eventInit() {
        this.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int i) {
                int childAdapterPosition = recyclerView.getChildAdapterPosition(GuessActivity.this.snapHelper.findSnapView(GuessActivity.this.layoutManager));
                System.out.println(childAdapterPosition + "/" + GuessActivity.this.adapter.guessVideoList.size());
                if (childAdapterPosition + 3 <= GuessActivity.this.adapter.guessVideoList.size()) {
                    return;
                }
                if (i == 0) {
                    GuessActivity.this.handler.sendEmptyMessage(0);
                    System.out.println("停止滚动");
                } else if (i == 1) {
                    System.out.println("拖动");
                    VideoUtil.postGuessVideoList(GuessActivity.this.adapter.guessVideoList);
                } else if (i == 2) {
                    System.out.println("惯性滑动");
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void setRecyclerView() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        this.layoutManager = linearLayoutManager;
        linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
        this.recyclerView.setLayoutManager(this.layoutManager);
        VideoGuessAdapter videoGuessAdapter = new VideoGuessAdapter(this);
        this.adapter = videoGuessAdapter;
        this.recyclerView.setAdapter(videoGuessAdapter);
    }

    /* access modifiers changed from: package-private */
    public void videoInit() {
        VideoUtil.postGuessVideoList(this.adapter.guessVideoList);
        new Thread(new Runnable() {
            /* class cn.yeyiu.sexyiu.activity.GuessActivity.AnonymousClass2 */

            public void run() {
                do {
                    try {
                        Thread.sleep(200);
                    } catch (Exception e) {
                        e.printStackTrace();
                        return;
                    }
                } while (GuessActivity.this.adapter.guessVideoList.size() < 3);
                GuessActivity.this.handler.sendEmptyMessage(0);
            }
        }).start();
    }

    /* access modifiers changed from: package-private */
    public void handlerInit() {
        this.handler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
            /* class cn.yeyiu.sexyiu.activity.GuessActivity.AnonymousClass3 */

            public boolean handleMessage(Message message) {
                if (message.what != 0) {
                    return true;
                }
                GuessActivity.this.adapter.notifyDataSetChanged();
                return true;
            }
        });
    }

    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity
    public void onStop() {
        super.onStop();
    }
}
